﻿using Microsoft.EntityFrameworkCore;
using Volo.Abp.EntityFrameworkCore;
using Efcore_Test.Entities;

namespace Efcore_Test.Data;

/// <summary>
/// 程序包管理控制台运行 Code-First
///    生成迁移
///    Add-migration   生成迁移脚本
///    Update-Database   开始迁移
///    
///    脚本 sql
///    Remove-migration    删除脚本
///    Script-migration  生成脚本
///    Script-migration  xxx   xxx 指定版本区间   Script-migration  project1   project2
///    Script-migration  xxx  从哪个版本开始生成脚本
///    
/// 程序包管理控制台运行 DB-First
///     Scaffold-DbContext '数据库连接字符串'  EntityFrameworkCore.EntityFrameworkCore.Sqlserver
/// </summary>
/// <param name="options"></param>
public class Efcore_TestDbContext : AbpDbContext<Efcore_TestDbContext>
{
    /// <summary>
    /// 
    /// </summary>
    public DbSet<Article> articles { get; set; }

    public DbSet<Comment> comments { get; set; }

    public DbSet<User> users { get; set; }

    public DbSet<Leave> leaves { get; set; }

    public DbSet<OrgUnit> orgUnits { get; set; }

    public DbSet<Order> orders { get; set; }

    public DbSet<Delivery> deliveries { get; set; } 

    public DbSet<Student> students { get; set; }

    public DbSet<Teacher> teachers { get; set; }

    public Efcore_TestDbContext(DbContextOptions<Efcore_TestDbContext> options)
        : base(options)
    {

    }

    /// <summary>
    /// 数据库连接
    /// </summary>
    /// <param name="optionsBuilder"></param>
    protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
    {
        base.OnConfiguring(optionsBuilder);
        //optionsBuilder.UseLoggerFactory(LoggerFactory);  //日志系统
        //optionsBuilder.LogTo(msg => Console.WriteLine(msg)); //日志系统
        //optionsBuilder.LogTo(Console.WriteLine, LogLevel.Information);
    }

    protected override void OnModelCreating(ModelBuilder builder)
    {
        base.OnModelCreating(builder);

        /* Include modules to your migration db context */

        /* Configure your own entities here */
        builder.ApplyConfigurationsFromAssembly(this.GetType().Assembly);
    }
}
